package com.sleep.satokendemo.fegin;

import com.sleep.satokendemo.entry.feign.*;
import com.sleep.satokendemo.fegin.fallback.ExceptionFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

@FeignClient(name = "wx",url = "https://api.weixin.qq.com",fallbackFactory = ExceptionFallbackFactory.class)
public interface WxFeign {

    @GetMapping("/cgi-bin/token")
    WxToken getWxToken(@RequestParam String grant_type,@RequestParam String appid,@RequestParam String secret);

    @PostMapping(value = "/cgi-bin/message/template/send")
    String sendTemplate(@RequestParam String access_token, @RequestBody MessageForm messageForm);

    @PostMapping("/cgi-bin/message/subscribe/bizsend")
    String sendSubscribe(@RequestParam String access_token, @RequestBody SubscribeForm subscribeForm);

    /**
     * 获取用户unionid 小程程序和公众号需要绑定到公众平台
     * @param appid
     * @param secret
     * @param code wx.login返回的code
     * @param grant_type 填authorization_code
     * @return AccessTokenRes
     */
    @GetMapping("/sns/oauth2/access_token")
    AccessTokenRes getUnionidByCode(@RequestParam String appid, @RequestParam String secret, @RequestParam String code, @RequestParam String grant_type);

    /**
     * 通过openid获取unionid
     * @param access_token
     * @param openid
     * @param lang
     * @return UnionIdRes
     */
    @GetMapping("/cgi-bin/user/info")
    UnionIdRes getUnionIdByOpenId(@RequestParam String access_token, @RequestParam String openid, @RequestParam String lang);
}
